const { get, post } = require('../../../../utils/request.js')
const EventBus = require('../../../../utils/eventBus.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showPassword: false,
    fixdepositData: {},
    leaveMoney: "",
    lostMoney: "",
    rate: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad({ id }) {
    get(`fixdeposit/get/${id}`, { "joinDomain": "bankAccount" }, (data) => {
      if (data.tag) {
        data.tags = data.tag.split(',');
      }

      this.setData({
        fixdepositData: data
      })

    })

    get(`fixdeposit/calculatePenalty`,
      {
        "fixDepositId": id,
        "unicode": wx.getStorageSync('unicode')
      }, ({ leaveMoney, lostMoney, rate }) => {
        this.setData({
          leaveMoney: leaveMoney,
          lostMoney: lostMoney,
          rate: rate
        })
      })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onSubmit() {
    const dataId = this.data.fixdepositData.id;

    post(`bankstatement/fixOut/${dataId}`, null, () => {
      EventBus.emit('home.freshAllData')

      setTimeout(() => {
        wx.switchTab({
          url: '/pages/tabBar/summary/home',
        })
      }, 2000);

      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000
      })
    })

  },
  submitData() {
    this.setData({
      showPassword: true
    })
  }
})